package com.xuecheng.search.controller;

import com.xuecheng.api.search.CoursePubSearchApi;
import com.xuecheng.api.search.model.dto.CoursePubIndexDTO;
import com.xuecheng.api.search.model.qo.QueryCoursePubModel;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.search.service.CoursePubSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CoursePubSearchController implements CoursePubSearchApi {
    @Autowired
    private CoursePubSearchService coursePubSearchService;

    /**
     * 分页查询课程发布信息
     *
     * @param pageParams 分页查询参数
     * @param queryModel 查询条件
     * @return 课程发布信息
     */
    @PostMapping("course_index")
    public PageVO<CoursePubIndexDTO> coursePubIndexByCondition(PageRequestParams pageParams, @RequestBody QueryCoursePubModel queryModel) {
        PageVO<CoursePubIndexDTO> pageVO = this.coursePubSearchService.coursePubIndexByCondition(pageParams, queryModel);
        return pageVO;
    }

    /**
     * 根据id查询课程发布数据
     *
     * @param coursePubId id
     * @return 课程发布数据
     */
    @Override
    @GetMapping("course_index/{coursePubId}")
    public CoursePubIndexDTO getCoursePubIndexById(@PathVariable Long coursePubId) {
        CoursePubIndexDTO dto = this.coursePubSearchService.getCoursePubIndexById(coursePubId);
        return dto;
    }

    /**
     * 根据课程发布Id查询课程发布索引数据
     *
     * @param coursePubId 课程发布信息id
     * @return 课程发布信息
     */
    @Override
    @GetMapping("l/course-index/{coursePubId}")
    public RestResponse<CoursePubIndexDTO> getCoursePubIndexById4s(@PathVariable Long coursePubId) {
        RestResponse<CoursePubIndexDTO> response = this.coursePubSearchService.getCoursePubIndexById4s(coursePubId);
        return response;
    }
}
